<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
var jsonObj = new Object();
$(function(){
	
	var roleName = $("#roleName").val();
	if(roleName != "ADMINISTRATOR" || roleName == null){
		$("#delButton").hide();
	}
	
	$("#dialogDiv").dialog({
		title:'报修信息维护',
		width:700,
		height:210,
		top:35,
		closed:true,
		madel:true,
		cache:false,
		onClose:function(){
			$("#dialogIframe").attr("src","");
		}
	});
	
	$("#addButton").click(function(){
		$("#dialogIframe").attr("src","theRepairAdd.action");
		$("#dialogDiv").dialog('open');
	});
	
	$("#editButton").click(function(){
		var checkObj = $("input[name='id']:checked");
		if(checkObj.size()==1){
			var id = checkObj.val();
			$.messager.confirm({
				title:'提示',
				msg:'确认已修理吗',
				top:35,
				fn:function(r){
					if(r){
						$.ajax({
							type:'POST',
							url:'theRepairEdit.action',
							data:{id:id},
							success:function(msg){
								if(msg.status=="200"){
									$("#theRepairList").datagrid({queryParams:getParams()});
								}else{
									$.messager.alert("提示","失败");
								}
							}
						});
					}
				}
			});
		}else{
			$.messager.alert("提示","选一条记录");
		}
	});
	
	$("#searchButton").click(function(){
		$("#theRepairList").datagrid({queryParams:getParams()});
	});
	
	$("#empty").click(function(){
		$("#status").combobox('setValue',"");
		$("#theRepairList").datagrid({queryParams:getParams()});
	});
	
	$("#delButton").click(function(){
		var checkObj = $("input[name='id']:checked");
		if(checkObj.size()==1){
			var id = checkObj.val();
			$.messager.confirm({
				title:'提示',
				msg:'确认删除吗',
				top:35,
				fn:function(r){
					if(r){
						$.ajax({
							type:'POST',
							url:'theRepairDel.action',
							data:{id:id},
							success:function(msg){
								if(msg.status=="200"){
									$("#theRepairList").datagrid({queryParams:getParams()});
								}else{
									$.messager.alert("提示","失败");
								}
							}
						});
					}
				}
			});
		}else{
			$.messager.alert("提示","选一条记录");
		}
	});
	
	$("#theRepairList").datagrid({
		url:'<c:url value="theRepairList.action" />',
		queryParams:getParams(),//pagination:true,
		toolbar:'#carCategoryToolbar',
		pagination:true,
		pagePosition:'bottom',
		pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    pageList:[10, 20, 30, 40], 
	    fitColumns:true,
	    selectOnCheck:false,
	    //sortName: 'studentId',
	    //sortOrder: 'asc',
	    remoteSort: false,
	    singleSelect:false,
	    rownumbers:true,
	    striped:true,
	    columns:[[
	    	{field:'id',title:'',width:10,align:'center',hidden:status,formatter:function(value,row,index){
	    		return '<input name="id" type="checkbox" value="'+value+'" />';
	    	}},
	    	{field:'dormitory',title:'寝室号',width:50,align:'center'},
	    	{field:'content',title:'内容',width:50,align:'center'},
	    	{field:'studentId',title:'学号',width:70,align:'center'},
	    	{field:'cnName',title:'姓名',width:50,align:'center'},
	    	{field:'time',title:'时间',width:70,align:'center',sortable:true,formatter: function(value,row,index){
				var str="";
				if(value){
					str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss").replace(" ","<br/>");
				}
				return str;
			}},
	    	{field:'status',title:'状态',width:40,align:'center',formatter:function(value,row,index){
	    		if(value==1)
	    			return "【未修理】";
	    		else
	    			return "已修理";
	    	}},
	    ]],
		onClickRow:function(index,row){
			$("input[type=checkbox]").val([row.id]).attr("checked",true);
	    }
	});
	
});


function getParams(){
	if($("#status").combobox('getValue') != "" && $("#status").combobox('getValue') != null){
		jsonObj.status = $("#status").combobox('getValue');
	}else{
		jsonObj.status = null;
	}
	jsonObj.studentId = $("#studentId").val();
	jsonObj.roleName = $("#roleName").val();
	jsonObj.storiedBuilding = $("#storiedBuilding").val();
	return jsonObj;
}

function closeDialog(){
	$("#dialogDiv").dialog('close');
	$("#theRepairList").datagrid({queryParams:getParams()});
}